package com.weipai.demo.util;

import github.wxpay.sdk.IWXPayDomain;
import github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class MyWxConfig extends WXPayConfig {
    private final static String APP_ID = PropUtils.getString("appId");

    private final static String MCH_ID = PropUtils.getString("mchId");

    private final static String APP_KEY = PropUtils.getString("key");

    public final static String Notify_Url = PropUtils.getString("Notify_Url");

    private final static String wxEwmPayNotify_Url = PropUtils.getString("wxEwmPayNotify_Url");
    public final static String basePath = "https://api.mch.weixin.qq.com/pay/unifiedorder";//统一下单请求地址
    private byte[] certData;

    public MyWxConfig() throws Exception {
        String certPath = "/path/to/apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public String getAppID() {
        return APP_ID;
    }

    public String getMchID() {
        return MCH_ID;
    }

    public String getKey() {
        return APP_KEY;
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return null;
    }
}
